﻿using System.Collections.Generic;

public delegate void ViewEvent(object[] allParams);

public class ViewEventManager : Singleton<ViewEventManager>
{
    Dictionary<int, ViewEvent> eventDictionary = new Dictionary<int, ViewEvent>();

    public void RegistEventHandler(ViewEventName eventName, ViewEvent eventHandler)
    {
        int eventNameInt = (int)eventName;
        if (eventDictionary.ContainsKey(eventNameInt))
        {
            eventDictionary[eventNameInt] += eventHandler;
        }
        else
        {
            eventDictionary[eventNameInt] = eventHandler;
        }
    }

    public void UnRegistEventHandler(ViewEventName eventName, ViewEvent eventHandler)
    {
        int eventNameInt = (int)eventName;
        if (eventDictionary.ContainsKey(eventNameInt))
        {
            eventDictionary[eventNameInt] -= eventHandler;
        }
    }

    public void SendEvent(ViewEventName eventName, params object[] allParams)
    {
        int eventNameInt = (int)eventName;
        if (eventDictionary.ContainsKey(eventNameInt))
        {
            if (eventDictionary[eventNameInt] != null)
                eventDictionary[eventNameInt](allParams);
        }
    }

}
